package zerous.infinite.core.entity;

import com.badlogic.gdx.graphics.g2d.*;
import zerous.infinite.*;
import zerous.infinite.core.*;
import com.badlogic.gdx.math.*;

public class Player extends Entity
{
	static Sprite face, right, left, back;
	
	Item[] backpack;

	public Player() {
		velocity.set(1, 1);
		face = initSprite(Assets.PLAYER_FACE);
		right = initSprite(Assets.PLAYER_RIGHT);
		left = initSprite(Assets.PLAYER_LEFT);
		back = initSprite(Assets.PLAYER_BACK);
		texture = face;
	}

	private Sprite initSprite(TextureRegion r) {
		Sprite result = new Sprite(r);

		//result.setSize(result.getWidth(), result.getHeight());

		return result;
	}

	public void draw(Batch batch) {
		if (controller != null) direction.set(controller.getDirection());
		position.add(velocity.x*direction.x, velocity.y*direction.y);

		if (direction.x > 0.7) {
			texture = right;
		} else if (direction.x < -0.7) {
			texture = left;
		}

		if (direction.y > 0.7) {
			texture = back;
		} else if (direction.y < -0.7) {
			texture = face;
		}

		texture.setPosition(position.x, position.y);
		
		texture.draw(batch);
	}
}
